<%layout("/common/_layout.html"){ %>
<%#ajax userTable:{%>
<div class="am-cf am-padding">
  <div class="am-fl am-cf"> <strong class="am-text-primary am-text-lg">订单管理</strong>
    /
    <small>商品订单管理</small>
  </div>
</div>
<div class="am-g">
  <div class="am-u-sm-12">
    <form class="am-form" id="list-form" action="${base}/productorder/list" method="post">
      <input type="hidden" id="keywords" name="keywords" value='${keywords!""}' />
      <input type="hidden" id="isExport" name="isExport" value='${isExport!"0"}' />
      <table class="am-table am-table-bordered am-table-radius table-main" style="padding:0;">
        <tbody>
          <tr>
            <th class="am-text-middle">订单编号</th>
            <td>
              <div class="am-u-sm-10">
                <input type="text" id="order_id" class="am-form-field am-input-sm" value="${order_id!}" />
              </div>
            </td>
            <th class="am-text-middle">订单状态</th>
            <td>
              <div class="am-u-sm-10">
                <select data-am-selected="{btnSize:'sm'}" id="order_status" name="order_status" >
                  <option value="-1" <%if(order_status! == "-1") {%>
                    selected
                    <%}%>>全部</option>
                  <option value="5" <%if(order_status! == "5") {%>
                    selected
                    <%}%>>新建</option>
                  <option value="10" <%if(order_status! == "10") {%>
                    selected
                    <%}%>>成功</option>
                  <option value="15" <%if(order_status! == "15") {%>
                    selected
                    <%}%>>失败</option>
                  <option value="20" <%if(order_status! == "20") {%>
                    selected
                    <%}%>>异常</option>
                </select>
              </div>
            </td>
          </tr>
          <tr>
            <th class="am-text-middle">销售人员手机号</th>
            <td>
              <div class="am-u-sm-10">
                <input type="text" id="sales_tel" class="am-form-field am-input-sm" value="${sales_tel!}" />
              </div>
            </td>
            <th class="am-text-middle">所属地市</th>
            <td>
              <div class="am-u-sm-10">
                <input type="text" id="sales_city" class="am-form-field am-input-sm" value="${sales_city!}" />
              </div>
            </td>
          </tr>









          <tr>
            <th class="am-text-middle">客户手机号</th>
            <td>
              <div class="am-u-sm-10">
                <input type="text" id="customer_tel" class="am-form-field am-input-sm" value="${customer_tel!}" />
              </div>
            </td>
            <th class="am-text-middle">IMEI</th>
            <td>
              <div class="am-u-sm-10">
                <input type="text" id="contract_id" class="am-form-field am-input-sm" value="${contract_id!}" />
              </div>
            </td>
          </tr>
          <tr>
            <th>店员身份</th>
            <td>
              <div class="am-u-sm-10">
                <select data-am-selected="{btnSize:'sm',maxHeight: 400}" name="member_type" id="member_type">
                  <option value="0" <%if(member_type! == "0"){%>
                  selected
                  <%}%>>全部</option>
                  <option value="1" <%if(member_type! == "1"){%>
                  selected
                  <%}%>>店长</option>
                  <option value="2" <%if(member_type! == "2"){%>
                  selected
                  <%}%>>店员</option>
                  <option value="3" <%if(member_type! == "3"){%>
                  selected
                  <%}%>>泛店员</option>
                </select>
              </div>
            </td>
            <th class="am-text-middle">销售时间</th>
            <td>
              <div class="am-u-sm-10">
                <div class="am-form am-form-inline">
                  <div class="am-form-group am-form-icon"> <i class="am-icon-calendar"></i>
                    <input type="text" class="am-form-field am-input-sm" placeholder="开始时间" data-am-datepicker id="start_date" value="${start_date!}" readonly></div>
                  <div class="am-form-group">至</div>
                  <div class="am-form-group am-form-icon"> <i class="am-icon-calendar"></i>
                    <input type="text" class="am-form-field am-input-sm" placeholder="结束时间" data-am-datepicker id="end_date" value="${end_date!}" readonly></div>
                </div>
                <span class="am-text-nowrap am-text-danger am-l am-fl">*默认显示当月数据</span>
              </div>
            </td>
          </tr>





          <tr>


          </tr>












          <tr>

            <th class="am-text-middle">客户经理</th>
            <td>
              <div class="am-u-sm-10">
                <label class="am-radio-inline">
                  <input type="radio" id="beMgr" name="isMgr" value="1" data-am-ucheck <%if(isMgr! ==
                  "1"){%>
                  checked
                  <%}%> > 是
                </label>
                <label class="am-radio-inline">
                  <input type="radio" id="notMgr" name="isMgr" value="0" data-am-ucheck <%if(isMgr! ==
                  "0"){%>
                  checked
                  <%}%>> 否
                </label>
                <label class="am-radio-inline">
                  <input type="radio" id="whatever" name="isMgr" value="2" data-am-ucheck
                  <%if(!has(isMgr)||(isMgr! == "2")){%>
                  checked
                  <%}%>> 全部
                </label>
              </div>
            </td>



            <td colspan="2">
              <div align='right'>
                <button type="button" class="am-btn am-btn-default am-btn-sm am-text-secondary" id="submit-btn">搜索</button>
                <%if(so.hasPermission("PRODUCT_ORDER_EXPORT")) {%>
                <button type="button" class="am-btn am-btn-default am-btn-sm am-text-secondary" id="export-btn">导出</button>
                <%}%></div>
            </td>
          </tr>
          <tr id='downloadAlertZone' style="display:none">
            <td colspan="4">
              <div id='downloadAlert' class="am-alert am-alert-warning" data-am-alert>
                <p id="downloadAlertMsg">导出失败</p>
              </div>
            </td>
          </tr>
          <tr id="download" style="display:none">
            <td colspan="4">
              <div align='center'>
                <a id="downloadlink" href="#">导出成功，点击下载</a>
              </div>
            </td>
          </tr>
        </tbody>
      </table>
    </form>
  </div>
  <div class="am-u-sm-12 am-u-md-12" style="padding:0 1.6rem 1.6rem 1rem;margin:0;">
    <div class="am-btn-toolbar" style="padding-left:.5rem;"></div>
  </div>
</div>
<div class="am-g">
  <div class="am-u-sm-12">
    <div class="am-scrollable-horizontal">
      <table class="am-table am-table-striped am-table-hover table-main">
        <thead>
          <tr class="am-text-nowrap">
            <th class="table-title">订单编号</th>
            <th class="table-title">订单状态</th>
            <th class="table-title">商品名称</th>
            <th class="table-title">商品属性</th>
            <th class="table-title">商品单价</th>
            <th class="table-title">IMEI</th>
            <th class="table-title">销售人员</th>
            <th class="table-title">销售人员身份</th>
            <th class="table-title">销售电话</th>
            <th class="table-title">销售员工号</th>
            <th class="table-title">销售员渠道名称</th>
            <th class="table-title">销售员渠道编码</th>
            <th class="table-title">客户电话</th>
            <th class="table-title">销售时间</th>
            <th class="table-title">所属地市</th>
            <th class="table-title">合约编码</th>
            <th class="table-title">合约信息</th>
            <th class="table-title">渠道类型</th>
            <th class="table-title">区县</th>
            <th class="table-title">是否客户经理</th>
          </tr>
        </thead>
        <tbody>
          <%for(list in pager.list!){%>
          <tr>
            <td>${list.OrderID}</td>
            <td>${list.OrderStatus}</td>
            <td>${list.ProductName}</td>
            <td>${list.ProductSkuTitle}</td>
            <td>${list.product_price}</td>
            <td>${list.IMEI}</td>
            <td>${list.SalesName}</td>
            <td>${list.member_type}</td>
            <td>${list.SalesTel}</td>
            <td>${list.emp_code}</td>
            <td>${list.DisplayName}</td>
            <td>${list.NumCode}</td>            
            <td>${list.CustomerTel}</td>
            <td class="am-text-nowrap">${list.CreateTime}</td>
            <td>${list.CityName}</td>
            <td>${list.ContractId}</td>
            <td>${list.ContractInfo}</td>


            <td>${list.class_name}</td>
            <td>${list.areaName}</td>
            <td>${list.is_accounts_manager}</td>



          </tr>
          <%}%></tbody>
      </table>
    </div>
    <div class="am-cf">
      <!-- 分页 -->
      <%if (pager.list.~size >
      0){%>
      <div class="am-fr">
        <% include("/admin/common_pager.tpl"){}%></div>
      <%}else{%>
      <div class="am-kai">
        <h3>没有找到任何记录!</h3>
      </div>
      <%}%></div>

  </div>
</div>
<script type="text/javascript">
    $(function(){
      var keywordsObj = {};

      function setKeyWords(){
        if($("#order_id").val())
              keywordsObj.order_id = $("#order_id").val();
            if($("#customer_tel").val())
              keywordsObj.customer_tel = $("#customer_tel").val();
          if($("#member_type").val())
              keywordsObj.member_type = $("#member_type").val();
            if($("#sales_tel").val())
              keywordsObj.sales_tel = $("#sales_tel").val();
            if($("#sales_city").val())
              keywordsObj.sales_city = $("#sales_city").val();
            if($("#contract_id").val())
              keywordsObj.contract_id = $("#contract_id").val();
            if($("#start_date").val())
              keywordsObj.start_date = $("#start_date").val();
            if($("#end_date").val())
              keywordsObj.end_date = $("#end_date").val();
            if($("#order_status").val())
              keywordsObj.order_status = $("#order_status").val();


          var $checkObj = $("input[name='isMgr']");
          for (var i = 0; i < $checkObj.length; i++) {
              if ($checkObj[i].checked) {
                  keywordsObj.isMgr = $checkObj[i].value;
                  break;
              }
          }


            var keywords = "";
            if(!$.isEmptyObject(keywordsObj)){
              keywords = JSON.stringify(keywordsObj);
            }
            console.log("keywords = "+ keywords);

            $("#keywords").val(keywords);
      }

      $("#submit-btn").on("click",function(){
        setKeyWords();
        $("#isExport").val("0");
        $("#list-form").submit();
      });
      $('#downloadAlert').on('closed.alert.amui', function() {
        $('#downloadAlertZone').hide();
      });

      $("#export-btn").on("click",function(){
          $('#download').hide();
          $('#downloadAlertZone').hide();
          //loading层
          var index = parent.layer.load(0, {
              shade: [0.1,'#fff'] //0.1透明度的白色背景
          });
          setKeyWords();
          $("#isExport").val("1");
          //$("#list-form").submit();
          var formParam = $("#list-form").serialize();//序列化表格内容为字符串
          console.log('formParam='+formParam);
          $.ajax({
            type:'post',
            url:'${base}/productorder/list',
            data:formParam,
            success:function(data){
              console.log(data);
              if(data.status==1){
                 $('#downloadlink').text(data.message);
                 $('#downloadlink').attr('href',data.url);
                 $('#download').show();
              }else{
                 $('#downloadAlertMsg').text(data.message);
                 $('#downloadAlertZone').show();
              }
              parent.layer.close(index);
            },
            error: function() {
               parent.layer.close(index);
            }
          });
        });
    });
  </script>
<%}%>
<%}%>